#! /bin/sh
#
# System startup script for the Ntripcaster
#
### BEGIN INIT INFO
# Provides:          ntripcaster
# Required-Start:    $network
# Should-Start:
# Required-Stop:     $network
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Ntripcaster
# Description:       Start the ntripcaster daemon
### END INIT INFO

CASTER_CONFIG=/etc/ntripcaster/
PROG=/usr/bin/ntripcaster

# Source SuSE config
. /etc/rc.status

rc_reset
case "$1" in
    start)
        pushd $CASTER_CONFIG >/dev/null
        DIRS=`find -maxdepth 1 -mindepth 1 -type d -and -not -name "_*" -and -not -name "templates" -printf "%f "`
        popd >/dev/null
        echo -n "Starting Ntripcaster daemon service $DIRS"
        if [ -z "$DIRS" ]; then
          $PROG start >/dev/null 2>/dev/null
        else
          for i in $DIRS
          do
             $PROG start $i >/dev/null 2>/dev/null
          done
        fi
        # fake status
        echo >/dev/null
        rc_status -v
        ;;
    stop)
        pushd $CASTER_CONFIG >/dev/null
        DIRS=`find -maxdepth 1 -mindepth 1 -type d -and -not -name "_*" -printf "%f "`
        popd >/dev/null
        echo -n "Shutting down Ntripcaster daemon service $DIRS"
        if [ -z "$DIRS" ]; then
          $PROG stop >/dev/null 2>/dev/null
        else
          for i in $DIRS
          do
             $PROG stop $i >/dev/null 2>/dev/null
          done
        fi
        # fake status
        echo >/dev/null
        rc_status -v
        ;;
    try-restart)
        $0 status >/dev/null && $0 restart
        rc_status
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    force-reload)
        $0 try-restart
        rc_status
        ;;
    reload)
        $0 try-restart
        rc_status
        ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
        exit 1
        ;;
esac
rc_exit
